const express = require('express');
const bodyParser = require('body-parser')
const {getInterfaceInfo} = require("./knife4j/getInterfaceInfo");
const {pingAll} = require("./ip-check/pingInterface");
const {pingConfig} = require("../notifier.config");
const app = express();

// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))

// parse application/json
app.use(bodyParser.json())

app.get('/', function(req, res){
    res.send('hello world and express');
});

app.get('/ping', async function(req, response){
    response.writeHead(200, {
        'Content-Type': 'text/html;charset=utf-8'
    });
    response.write(`<p>doc.html账号密码：knife4j-admin/li-fly-knife</p>`);
    await pingAll(res => {
        response.write(res);
    });
    response.end();
});

app.post('/knife4j', async function(req, res){
    console.log(req.body)
    const chunk = await getInterfaceInfo();
    res.send(chunk);
});


app.listen(pingConfig.port, () =>
    console.log(`Example app listening on port ${pingConfig.port}!`)
);
